/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.generator.command.rule;

import ru.jSkyRoom.generator.command.Command;
import ru.rakev.matcher.Matcher;

/**
 *
 * @author Rakev
 */
public class SimpleRule<T> implements Rule<T> {

    private Matcher<T> matcher;
    private Command<T> command;

    public SimpleRule(Matcher<T> matcher, Command<T> command) {
        this.matcher = matcher;
        this.command = command;
    }

    @Override
    public boolean check(T item) {
        return matcher.matches(item);
    }

    @Override
    public T apply(T item) {
        if (check(item)) {
            return command.apply(item);
        } else {
            return item;
        }
    }
}
